<?php

class Default_Form_SendForFriend extends Zend_Form {
	
	const ENCODING              = 'UTF-8';
	const FULLNAME_MIN_LENGTH   = 0;
	const FULLNAME_MAX_LENGTH   = 50;
	const TITLE_MIN_LENGTH    	= 5;
	const TITLE_MAX_LENGTH    	= 200;
	
	public function init() {
		
		$this->setName('frmSendMailFriend');
		$id = new Zend_Form_Element_Hidden('link_bai_viet');
		$id->setDecorators(array('ViewHelper'));

        //Full name
        $fullname = self::addFullName();
        //Email from
        $emailFrom = self::addEmailFrom();
        //Email to
        $emailTo = self::addEmailTo();
        //Subject
        $subject = self::addSubject();
        //Message
        $message = self::addMessage();
        
        $this->addElements(array($id, $fullname, $emailFrom, $emailTo, $subject, $message));
	}
	
	/*
	 * Add full_name element
	 */
	protected function addFullName() {
        $fullnameNotEmpty = new Zend_Validate_NotEmpty();
        //Length validate
        $fullnameLength = new Zend_Validate_StringLength(self::FULLNAME_MIN_LENGTH, self::FULLNAME_MAX_LENGTH, self::ENCODING);
        $fullname = new Zend_Form_Element_Text('ten_nguoi_gui');
        $fullname	->addFilter('StripTags')
        			->addFilter('StringTrim')
	        		->setDecorators(array('ViewHelper'))
	        		->setRequired(true)
	        		->addValidator($fullnameLength)
	        		->addValidator($fullnameNotEmpty, true);
        return $fullname;
	}
	
	/*
	 * Add email element
	 */
	protected  function addEmailFrom() {
         $email = new Zend_Form_Element_Text('email_from');
         $emailNotEmpty = new Zend_Validate_NotEmpty();
         $email	->setRequired(true)
         		->addValidator($emailNotEmpty, true)
        		->setDecorators(array('ViewHelper'))
         		->addFilter('StripTags')
         		->addFilter('StringTrim')
         		->addValidator(new Zendhlt_Validate_Email());
         return $email;
	}
	
	/*
	 * Add email element
	 */
	protected  function addEmailTo() {
         $email = new Zend_Form_Element_Text('email_to');
         $emailNotEmpty = new Zend_Validate_NotEmpty();
         $email	->setRequired(true)
         		->addValidator($emailNotEmpty, true)
        		->setDecorators(array('ViewHelper'))
         		->addFilter('StripTags')
         		->addFilter('StringTrim')
         		->addValidator(new Zendhlt_Validate_Email());
         return $email;
	}

	/*
	 * Add Subject element
	 */
	protected function addSubject() {
		$notEmptysubject = new Zend_Validate_NotEmpty();
        //Length validate
        $subjectLength = new Zend_Validate_StringLength(self::TITLE_MIN_LENGTH, self::TITLE_MAX_LENGTH, self::ENCODING);
        $subject = new Zend_Form_Element_Text('tieu_de');
        $subject->addFilter('StripTags')
        		->addFilter('StringTrim')
        		->setDecorators(array('ViewHelper'))
        		->setRequired(true)
        		->addValidator($subjectLength)
        		->addValidator($notEmptysubject, true);
        
        return $subject;
	}

	/*
	 * Add Message element
	 */
	protected function addMessage() {
        $message = new Zend_Form_Element_Textarea('thong_diep');
        $message->addFilter('StripTags')
        		->addFilter('StringTrim')
        		->setDecorators(array('ViewHelper'))
        		->setAttrib('class', 'small-textarea')
        		->setRequired(true);
        
        return $message;
	}
	
}
